#!/bin/bash
mkdir -p data/uploads

# 检测操作系统并选择对应的可执行文件
if [[ "$OSTYPE" == "darwin"* ]]; then
    # macOS
    EXECUTABLE="./lan-chat-macos"
else
    # Linux
    EXECUTABLE="./lan-chat-linux"
fi

# 确保可执行文件存在
if [ ! -f "$EXECUTABLE" ]; then
    echo "错误: 找不到可执行文件 $EXECUTABLE"
    exit 1
fi

# 添加执行权限
chmod +x "$EXECUTABLE"

# 打开浏览器
if command -v open >/dev/null 2>&1; then
    open http://localhost:3000
elif command -v xdg-open >/dev/null 2>&1; then
    xdg-open http://localhost:3000
elif command -v explorer >/dev/null 2>&1; then
    explorer http://localhost:3000
fi

# 运行程序
$EXECUTABLE 